(clojure.core/require '[fx-clj.internal.util])
(fx-clj.internal.util/ns-start-loading 'fx-clj.elements)

(ns ^:no-doc fx-clj.elements
  (:import (javafx.scene Scene))
  (:require
    [fx-clj.impl.elements :refer [get-factory]]
    [fx-clj.internal.controls :as controls]
    [fx-clj.core.pset :as pset]
    [fx-clj.impl.util :refer [javadoc-link javadoc-link-str]]))

;; <<----------------------
(fx-clj.internal.util/ns-libs-loaded 'fx-clj.elements)
;; ---------------------->>

(declare stage)

;; =================================================

(def ^:private default-arglists '([id-class-kw? property-map? & content-or-children*]))

(defn- create-element-closure [full-class-name]
  (let []
    (fn create-element [& args]
      (let [factory (get-factory full-class-name)

            ;cls
            ;(-> factory meta :fx-clj.impl.elements/class)

            ;def-prop-closure
            ;(pset/lookup-default-property-closure cls)
            ]
        (pset/pset!* (factory) args)))))

(doseq [[kw full-class-name] controls/class-names]
  (let [sym (symbol (name kw))
        doc-string
        (str "Creates an instance of " (javadoc-link-str full-class-name)
             ".\nArguments processed as in [[pset!]].")

        closure (create-element-closure full-class-name)

        sym (with-meta sym
                       {:doc        doc-string
                        :doc/format :markdown
                        :arglists   default-arglists
                        :name       sym
                        :ns         *ns*})]
    (intern *ns* sym closure)))

(defn scene
  {:doc        (str "Creates an instance of " (javadoc-link Scene) " with the specified root node.")
   :doc/format :markdown}
  ([root] (Scene. root)))



(fx-clj.internal.util/ns-loaded 'fx-clj.elements)